/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Yasmine
 */
public class bdd {
    private String Login,Mdp,adresse,port,DbName;
    Connection con=null;
    public bdd(String login,String mdp,String adresse,String port, String DbName)
            {
                this.Login=login;
                this.Mdp=mdp;
                this.adresse=adresse;
                this.port=port;
                this.DbName=DbName;
    
                
            }
    
    public void connect()
            {
                 try {
                    Class.forName("oracle.jdbc.driver.OracleDriver");
                    this.con = DriverManager.getConnection("jdbc:oracle:thin:@"+this.adresse+":"+this.port+":"+this.DbName,this.Login,this.Mdp);
                } catch(Exception e){e.printStackTrace();}
        
            }
    
    public void disconnect()
            {   
                try {
                    this.con.close();
                } catch (SQLException ex) {
                    Logger.getLogger(bdd.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
    
    public boolean  set (String q)
        {
            Statement s;
            //System.out.println(q);
            try {
                s = con.createStatement();
                s.execute(q);
                s.close();
                return true; 
                }   
            catch(Exception e)
                {
                    return false;
                }
                
        }

        public ResultSet get (String q) throws SQLException
        {
            
            Statement s;
            s = con.createStatement();
            ResultSet rs = s.executeQuery(q);
        return  rs ;         
        }
        
}
